<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta_index" /}
    <style>
        .laytable-cell-1-0-3{
            height: auto !important;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" name="phone" placeholder="手机号" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    <select name="state">
                        <option value="">状态(全部)</option>
                        <option value="0">禁用</option>
                        <option value="1">启用</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="cancel">
                        <option value="">注销状态(全部)</option>
                        <option value="0">注销</option>
                        <option value="1">正常</option>
                    </select>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="listSearch">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <script type="text/html" id="listTableToolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                    <!--<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>-->
                </div>
            </script>

            <table id="listTable" lay-filter="listTable"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.state == 1){ }}
                <button class="layui-btn layui-btn-xs" lay-event="change">启用</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="change">禁用</button>
                {{#  } }}
            </script>
            <script type="text/html" id="listTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="room"><i class="layui-icon layui-icon-edit"></i>房间/桌号</a>
                <!--{{#  if(d.id ==1){ }}-->
                <!--<a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                <!--{{#  } else { }}-->
                <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                <!--{{#  } }}-->
            </script>
        </div>
    </div>
</div>
{include file="layout:_footer" /}
<script>
    var del_url = '{:url("store/remove")}';
    var add_url = '{:url("store/edit")}';
    var change_url = '{:url("store/change")}';
    var room_url = '{:url("store_table/index")}';
    layui.config({
        base: '__static__/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table','common'], function(){
        var $ = layui.$
            ,common = layui.common
            ,form = layui.form
            ,table = layui.table;

        //数据列表
        table.render({
            elem: '#listTable',
            url : "{:url('store/index')}",
            toolbar: '#listTableToolbar',
            cols : [[
                {type: 'checkbox'},
                {field: 'id', title: 'ID', align:"center"},
                {field: 'name', title: '店铺名', align:'center'},
                {field: 'images', title: '店铺图', align:'center',width:80,templet:  function(d){
                        if(d.images !="")
                            return '<div style="cursor:pointer;" id="layer-photos-demos" class="layer-photos-demo"><img src="'+d.images+'" alt="" style="width:80px; height:80px;" onclick="showBigImage(this)"></div>'
                        else
                            return '暂无图片'
                    }
                },
                {field: 'tel', title: '电话', align:'center'},
                {field: 'address', title: '地址', align:'center'},
                {field: 'wxapp_id', title: '店铺编号', align:'center'},
                {field: 'sort', title: '排序', align:'center'},
                {field: 'create_time', title: '添加时间', align:'center'},
                {field: 'state', title: '状态', align:'center',templet: '#buttonTpl'},
                {title: '操作', fixed:"right",align:"center",templet:'#listTableBar',width:200,}
            ]],
            page: true, //是否显示分页
            limits:[10,15,20,25,30],//显示
            limit: 15 //每页默认显示的数量
            ,height: document.documentElement.clientHeight/5*4
        });

        //监听搜索
        common.tableSearch('listSearch','listTable');

        //列表操作
        table.on('tool(listTable)', function(obj){
            var layEvent = obj.event, data = obj.data;
            if(layEvent === 'del'){ //删除
                common.tableDelete(del_url,data.id,'listTable');
            }else if (layEvent==='edit'){
                common.adminShow(add_url+'?id='+data.id,"编辑",'80%','80%','addEdit','listTable');
            }else if(layEvent==='change'){
                var state = data.state==1?0:1;
                var msg =  data.state==1?'确定要禁用此账号？':'确定启用此账号？';
                common.tableStatus(change_url,{id:data.id,state:state},'listTable',msg);
            }else if (layEvent==='room'){
                common.adminShow(room_url+'?id='+data.wxapp_id,"列表",'95%','95%','addEdit','listTable');
            }

        });

        //列表工具栏操作
        table.on('toolbar(listTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'del':common.tableDelete(del_url,checkStatus.data,'listTable');break;
                case 'add':common.adminShow(add_url,"添加",'80%','80%','addEdit','listTable');break;
            }
        });


    });
</script>
</body>
</html>

